package top.hjcwzx.wrench.limiter.strategy.algorithm;

import top.hjcwzx.wrench.limiter.enums.AlgorithmStrategyEnum;

import javax.annotation.Resource;

public class RateLimiterAlgorithmExecutor {

    @Resource
    private RateLimiterAlgorithmStrategyContext context;

    public boolean tryAccess(String key, int permits, AlgorithmStrategyEnum strategy) {
        RateLimiterAlgorithmStrategy limiter = context.getAlgorithm(strategy);
        return limiter != null && limiter.tryAcquire(key, permits);
    }
}
